﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DayPilot.Web.Mvc;
using DayPilot.Web.Mvc.Events.Calendar;
using GPS.DataAccessLayer;
using GPS.COMMON;
using System.Collections.Generic;


namespace GPS.Controllers.GPS_NghiepVu
{
    public class GPS_LichHoc_SchedController : Controller
    {
        //
        // GET: /GPS_LichHoc_Sched/
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Backend()
        {
            return new Dpc().CallBack(this);
        }

        class Dpc : DayPilotCalendar
        {

            protected override void OnInit(InitArgs e)
            {
                DbContextHelper<GPS_NVContext> _db = Singleton<DbContextHelper<GPS_NVContext>>.Inst;
                List<DKH_LH> _lst = _db.GetAll<DKH_LH>();
                List<Event> _lstEvents = new List<Event>();
                int i=0;
                foreach(var item in _lst)
                { 
                    i++;
                    Event _ev = new Event();
                    _ev.id = i;
                    _ev.text = item.KH_LH_GV_MA + " - " + item.KH_LH_PT_BIENSO;
                    _ev.eventstart = item.KH_LH_TUNGAY.Value;
                    _ev.eventend = item.KH_LH_DENNGAY.Value;
                    _lstEvents.Add(_ev);
                }
                Events =  from ev in _lstEvents select ev; //_lstEvents.AsEnumerable();

                DataIdField = "id";
                DataTextField = "text";
                DataStartField = "eventstart";
                DataEndField = "eventend";

                Update();
            }
        }
    }

    class Event
    {
        public int id;

        public string text;

        public System.DateTime eventstart;

        public System.DateTime eventend;
    }
}